<template>
  <div class="contentmain">
      <el-row>
          <el-col>
              <el-button type="danger" icon="el-icon-plus" @click="changestate">添加店铺</el-button>
          </el-col>
      </el-row>

      <el-table :data="td" style="width:100%" tooltip-effect="dark" v-loading="loading" element-loading-text="数据加载中...">
            <el-table-column prop="shopName" label="店铺名称">
            </el-table-column>
            <el-table-column prop="contactPerson" label="店长">
            </el-table-column>
            <el-table-column prop="shopMobile" label="联系电话">
            </el-table-column>
            <el-table-column prop="shopAddress" label="地址">
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                    size="mini"
                    @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button
                    size="mini"
                    type="danger"
                    @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
      </el-table>
        <!--表格-->
        <ShopForm>
        </ShopForm>
    <!-- <el-row>
        <el-col :span="8" :offset="16">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-size="10"
              layout="total, prev, pager, next, jumper"
              :total="pagecount">
            </el-pagination>
        </el-col>
      </el-row> -->
  </div>
</template>
<script>
import ShopForm from 'components/ShopForm/ShopForm'
    export default{
        data(){
            return{
                td:[],
                currentPage:1,
                pagecount:0,
                loading:false
            }
        },
        components:{
            ShopForm
        },
        mounted(){//请求接口获取数据
            this.getData()
        },
        computed:{
            getstate(){//监听dialog
                return this.$store.state.shoplist;
            }
        },
        watch:{
            getstate(va){//dialog有动静,重新请求接口获取参数
                if(va==true){
                    this.$store.state.shoplist=false
                    this.getData()
                }
            }
        },
        methods:{
            handleEdit(index,row){//提交当前行内容用于编辑
                this.$store.commit('ChangeShopForm',row)
            },
            handleDelete(index,row){//删除
                var _this=this
                this.$confirm('确认删除？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                var param = new URLSearchParams();
                param.append("shopId",row.shopId);
                axios.get("/shop/deleteByShopId.do",{params:param}).then(r=>{
                    if(r.data.code==200){
                        _this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        _this.getData()
                        }else{
                        _this.$message({
                            type: 'info',
                            message: r.data.message
                        });
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });          
                });
            },
            handleSizeChange(){//翻页

            },
            handleCurrentChange(){//翻页

            },
            changestate(){//请求dialog
                this.$store.commit('ChangeShopForm')
            },
            getData(v){//统一获取数据
                if(!this.$store.state.shiro){
                    return
                }
                var _this=this
                this.loading=true
                axios.get('/shop/listShop.do').then(r=>{
                    // console.log(r)
                    if(r.data.message=="not login"&&r.data.code==500){//权限拦截
                        _this.$message.error("访问者,请登录")
                        router.push('/Login');
                        return
                    }
                    if(r.data.code!=200){
                        _this.$message.error(r.data.message)
                        _this.loading=false
                        return
                    }
                    _this.td=[].concat(r.data.response.shopList)
                    _this.loading=false
                })
            }
        },
        beforeCreate(){//权限判断
            let _this=this
            if(!this.$store.state.shiro){
                _this.$router.push('/full')
            }
        }
    }
</script>
<style>

</style>
